package cn.jdy.plugins.wap.util;

import java.util.Formatter;
import java.util.Random;
import java.util.UUID;


/**
 * @title  微信接口公共方法
 * @author ningqian
 * @date   2017-3-30
 */

public class ChatUtil {
	 
	  /***
      * 时间戳
      * @return
      */
     public static String create_timestamp() {
         return Long.toString(System.currentTimeMillis() / 1000);
     }
	  
     /****
      * 随机串
      * @return
      */
     public static String create_nonce_str() {
         return UUID.randomUUID().toString();
     }
     
     /**
      * 获取微信签名模块中的辅助函数
      */
      public static String byteToHex(final byte[] hash) {
          Formatter formatter = new Formatter();
          for (byte b : hash)
          {
              formatter.format("%02x", b);
          }
          String result = formatter.toString();
          formatter.close();
          return result;
      }
     

 	
     /** 
      * 返回一个定长的随机字符串(只包含数字) 
      *  
      * @param length 
      *            随机字符串长度 
      * @return 随机字符串 
      */  
     public static String generateString(int length) {  
         String number = "0123456789"; 
         StringBuffer sb = new StringBuffer();  
         Random random = new Random();  
         for (int i = 0; i < length; i++) {  
             sb.append(number.charAt(random.nextInt(number.length())));  
         }  
         return sb.toString();  
     }  
 	
     
   
     public static void main(String[] args) {
         int max=20;
         int min=10;
         Random random = new Random();

         int s = random.nextInt(max)%(max-min+1) + min;
         System.out.println(s);
         System.out.println(generateString(20));
         System.out.println(generateString(23));
         System.out.println(generateString(23));
         System.out.println(generateString(23));
         System.out.println(generateString(23));
         System.out.println(generateString(23));
         System.out.println(generateString(23));
         System.out.println(generateString(23));
         System.out.println(generateString(23));
         System.out.println(generateString(23));
     }
   
   
     
}
